home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 5 #3 / IMG 46 Vol 5-3.iso / More Goodies / More For Your Game / Realmz / Character Master Source / Nemesis Framework / Sources / nemesis misc utilities.cpp < prev    next >
Text File  |  1996-07-03  |  3KB  |  159 lines

  1. //•••••••••••••••••••••••••••••••
  2. //    Some miscellaneous utilities
  3. //•••••••••••••••••••••••••••••••
  4.  
  5. #ifndef __QDOFFSCREEN__
  6.     #include"QDOffscreen.h"
  7. #endif
  8. #ifndef __PALETTES__
  9.     #include "Palettes.h"
  10. #endif
  11.  
  12. Boolean NemesisIsTrapAvailable( int trapNum )
  13. {
  14.     TrapType     trapType;
  15.     int            numToolboxTraps;
  16.     
  17.     if (trapNum & 0x0800)
  18.     {
  19.         trapType = ToolTrap;
  20.     }
  21.     else
  22.     {
  23.         trapType = OSTrap;
  24.     }
  25.  
  26.     if (trapType == ToolTrap)
  27.     {
  28.         trapNum = trapNum & 0x07FF;
  29.         if (NGetTrapAddress(_InitGraf,ToolTrap) == 
  30.             NGetTrapAddress(0xAA6E, ToolTrap))
  31.         {
  32.             numToolboxTraps = 0x0200;
  33.         }
  34.         else
  35.         {
  36.             numToolboxTraps = 0x0400;
  37.         }
  38.         if ( trapNum > numToolboxTraps)
  39.         {
  40.             return(false);
  41.         }
  42.     }
  43.     
  44.     return( NGetTrapAddress(trapNum, trapType) != 
  45.             NGetTrapAddress(_Unimplemented, ToolTrap));
  46. }
  47.  
  48. Boolean    NemesisWithinLimits( long theValue, long lowerLimit, long upperLimit )
  49. {
  50.     if( (theValue < lowerLimit) || (theValue > upperLimit) )
  51.         return false;
  52.     else
  53.         return true;
  54. }
  55.  
  56. GDHandle    NemesisGetRectsDevice( Rect theRect )
  57. {
  58.     SInt32        greatestArea, intersectArea;
  59.     GDHandle    deviceHdl = nil, deviceHdlToReturn = GetMainDevice();
  60.     Rect        intersectRect;
  61.  
  62.     LocalToGlobal( &topLeft(theRect) );
  63.     LocalToGlobal( &botRight(theRect) );
  64.     
  65.     deviceHdl = LMGetDeviceList();
  66.     greatestArea = 0;
  67.  
  68.     while( deviceHdl != nil )
  69.     {
  70.         if( TestDeviceAttribute(deviceHdl,screenDevice) &&
  71.             TestDeviceAttribute(deviceHdl,screenActive) &&
  72.             SectRect(&theRect,&(*deviceHdl)->gdRect,&intersectRect))
  73.         {
  74.             intersectArea = (SInt32) ( intersectRect.right - intersectRect.left ) * 
  75.                                      ( intersectRect.bottom - intersectRect.top );
  76.  
  77.             if( intersectArea > greatestArea )
  78.             {
  79.                 greatestArea = intersectArea;
  80.                 deviceHdlToReturn = deviceHdl;
  81.             }
  82.         }
  83.         deviceHdl = GetNextDevice( deviceHdl );
  84.     }
  85.     return deviceHdlToReturn;
  86. }
  87.  
  88. int        NemesisMainDeviceDepth()
  89. {
  90.     GDHandle    mainDevice = nil;
  91.     int            currDepth = 1;
  92.     
  93.     mainDevice = GetMainDevice();
  94.  
  95.     if( mainDevice )    // Check for nil
  96.     {
  97.         currDepth = (*( (**mainDevice).gdPMap ))->pixelSize;
  98.     }
  99.  
  100.     return currDepth;
  101. }
  102.  
  103.  
  104. Boolean    NemesisSetDimmedColour( Rect theRect, RGBColor &oldForeColour )
  105. {
  106.     RGBColor    backColour, newForeColour;
  107.     GDHandle    targetDevice;
  108.     Boolean        newGrey = false;
  109.     
  110.     if( NemesisMainDeviceDepth() > 1 )
  111.     {
  112.         GetBackColor( &backColour );
  113.         GetForeColor( &oldForeColour );
  114.         
  115.         newForeColour = oldForeColour;
  116.         targetDevice = NemesisGetRectsDevice( theRect );
  117.         if( targetDevice )    // Check for nil
  118.             newGrey = GetGray( targetDevice, &backColour, &newForeColour );
  119.     }
  120.  
  121.     if(newGrey)
  122.         RGBForeColor( &newForeColour );
  123.     else
  124.         PenPat( &qd.gray );
  125.         
  126.     return newGrey;
  127. }
  128.  
  129. void    NemesisRestoreDimmedColour( RGBColor oldForeColour )
  130. {
  131.         RGBForeColor(&oldForeColour);
  132. }
  133.  
  134. Boolean    NemesisOptionKeyDown()
  135. {
  136.     KeyMap        theKeys;
  137.     GetKeys( theKeys );
  138.     
  139.     if( BitTst( &theKeys[1], kOptionKeyDown ) )
  140.         return true;
  141.     else
  142.         return false;
  143. }
  144.  
  145. Boolean    NemesisControlKeyDown()
  146. {
  147.     KeyMap        theKeys;
  148.     GetKeys( theKeys );
  149.     
  150.     if( BitTst( &theKeys[1], kControlKeyDown ) )
  151.         return true;
  152.     else
  153.         return false;
  154. }
  155.  
  156. void    NemesisPlaySound( int theSoundID )
  157. {
  158.     SHPlayByID( theSoundID, nil );
  159. }